<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>增加驾驶员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form" style="padding: 20px" id="driverForm">
    <div class="layui-form-item">
        <label class="layui-form-label">姓名:</label>
        <div class="layui-input-block">
            <input type="text" id="dirvername" name="dirvername" required  lay-verify="required" placeholder="请输入姓名" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别:</label>
        <div class="layui-input-block">
            <input type="radio" name="driversex" value="男" title="男" >
            <input type="radio" name="driversex" value="女" title="女" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">电话号码:</label>
        <div class="layui-input-block">
            <input type="text" id="drivertel" name="drivertel" required  lay-verify="required" placeholder="请输入电话号码" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">入职时间:</label>
        <div class="layui-input-block">
            <input type="text" id="driverentrytime" name="driverentrytime" required  lay-verify="required" placeholder="请输入入职时间" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">驾照类型:</label>
        <div class="layui-input-block">
            <select id="licenseid" name="license.licenseid">
                <option value=""></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">驾照号码:</label>
        <div class="layui-input-block">
            <input type="text" id="dirverlicenceno" name="dirverlicenceno" required  lay-verify="required" placeholder="请输入" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">所属部门:</label>
        <div class="layui-input-block">
            <select id="deptid" name="dept.deptid">
                <option value=""></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label userStatus">状态</label>
        <div class="layui-input-block" id="driverStatus">
            <input type="checkbox" name="status" id="status"  lay-skin="switch" lay-text="启用|禁用" value="1" checked lay-filter="cx">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">备注:</label>
        <div class="layui-input-block">
            <input type="text" id="remark" name="remark" required  lay-verify="required" placeholder="请输入备注" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="addDriver" id="addBtn">立即添加</button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">取消</button>
        </div>
    </div>

</form>
<script type="text/javascript" src="<%=request.getContextPath()%>/static/layui/layui/layui.js"></script>
<script>
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;

        //绑定时间插件到生日文本框中
        laydate.render({
            elem:'#driverentrytime',
            theme: 'grid'
        });

        var av=form.on('switch(cx)', function(data){
            cx=1-$("#status").val();
            $("#status").val(cx);
            console.log(cx);

        });


        $.ajax({
            url:'/user/selectDept',
            type:'GET',
            success:function (res) {
                for(var i=0;i<res.length;i++){
                    var optionitem=$("<option></option>");
                    optionitem.attr("value",res[i].deptid);
                    optionitem.append(res[i].deptname);
                    $("#deptid").append(optionitem);
                }
                form.render('select'); //刷新select选择框渲染
            }
        });

        $.ajax({
            url:'/driver/license',
            type:'GET',
            success:function (res) {
                for(var i=0;i<res.length;i++){
                    var optionitem=$("<option></option>");
                    optionitem.attr("value",res[i].licenseid);
                    optionitem.append(res[i].licensetype);
                    $("#licenseid").append(optionitem);
                }
                form.render('select'); //刷新select选择框渲染
            }
        });
        //提交表单
        form.on("submit(addDriver)",function(data) {
            $.ajax({
                type: "get",
                url: "/driver/addDriver",
                data:$('#driverForm').serialize() ,
                success: function (res) {
                    if(res.code==200){
                        layui.layer.msg(res.msg);
                        //关闭窗口ifram
                        var index1=parent.layer.getFrameIndex(window.name)
                        setTimeout(function () {
                            parent.layer.close(index1);
                            window.parent.location.reload();
                        },1000)
                    }else if(res.code==-200){
                        layui.layer.msg(res.msg);
                        //关闭窗口ifram
                        var index1=parent.layer.getFrameIndex(window.name)
                        setTimeout(function () {
                            parent.layer.close(index1);
                        },1000)
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>